#!/bin/bash
# Description: 此脚本用于打包dal_rticonnextdds压缩包，使用i之前请确认编译成功，且build/dal_rticonnextdds存在，
#              脚本执行成功后，将直接在指定目录下生成dal-rticonextdds-binary.zip文件

# Usage: ./package_dal_rticonnextdds.sh <path>

# 检查是否存在build/目录
if [ ! -d "build" ]; then
  echo "错误：当前路径下不存在 'build/' 目录"
  exit 1
fi

# 检查是否存在build/dal_rticonnextdds/目录
if [ ! -d "build/dal_rticonnextdds" ]; then
  echo "错误： 'build/' 目录下不存在 'dal_rticonnextdds/' 目录"
  exit 1
fi

# 创建usr目录
mkdir -p usr/lib
mkdir -p usr/bin/dal/dal_rticonnextdds/test
mkdir -p usr/bin/dal/dal_rticonnextdds/TestCases/ParticipantMonitor

# 创建目录结构
mkdir -p usr/bin/dal/dal_rticonnextdds/test
mkdir -p usr/bin/dal/dal_rticonnextdds/TestCases/ParticipantMonitor

# 移动文件
cp build/dal_rticonnextdds/libdal_rticonnextdds.so usr/lib/
cp build/dal_msg/libdal_typesupport_rticonnextdds_depends.so usr/lib/
cp build/dal_rticonnextdds/test/dal_rticonnextdds_test_* usr/bin/dal/dal_rticonnextdds/test/
cp dal_rticonnextdds/test/test_resource/DAL_RTI_USER_QOS_PROFILES.xml usr/bin/dal/dal_rticonnextdds/test/
cp build/dal_rticonnextdds/TestCases/ParticipantMonitor/dal_rticonnextdds_participant_monitor usr/bin/dal/dal_rticonnextdds/TestCases/ParticipantMonitor/

# 生成压缩包
zip -r dal-rticonextdds-binary.zip ./usr

# 删除./usr
rm -rf ./usr

echo "package_dal_rticonnextdds.sh 操作完成"